var IsIE = (navigator.appName=="Microsoft Internet Explorer") && parseInt(navigator.appVersion) >=4;

function $(elementId)
{
	if ( typeof elementId == 'string' )
	{
		return document.getElementById(elementId);
	}
	return elementId;
}

var $C=function(tag)
{
   return document.createElement(tag);
}
var $N = function(s)
{
	return document.getElementsByName(s);
}

function getElement(id) 
{
	return $(id);
}

Array.prototype.contains = function(obj)
{
	for ( var i=0 ; i < this.length ; ++i )
	{
		if ( this[i] == obj )
		{
			return true;
		}
	}
	return false;
};

Array.prototype.remove = function(obj)
{
	for ( var i=0 ; i < this.length ; ++i )
	{
		if ( this[i] == obj )
		{
			if ( i > this.length/2 )
			{
				for ( var j=i ; j < this.length-1 ; ++j )
				{
					this[j] = this[j+1];
				}
				this.pop();
			}
			else
			{
				for ( var j=i ; j > 0 ; --j )
				{
					this[j] = this[j-1];
				}
				this.shift();
			}
			break;
		}
	}
};

Array.prototype.clear = function()
{
	this.length = 0;
};

Object.prototype.Extends = function(BaseClass)
{
	if ( arguments.length >= 6 )
	{
		throw new Error(L_Only5ParametersSupport);
	}
	var base;
	if ( arguments.length > 1 )
	{
		var arg01 = arguments[1];
		var arg02 = arguments[2];
		var arg03 = arguments[3];
		var arg04 = arguments[4];
		base = new BaseClass(arg01, arg02, arg03, arg04);
	}
	else
	{
		base = new BaseClass();
	}
	for ( var key in base )
	{
		if ( !this[key] )
		{
			this[key] = base[key];
			if ( typeof(base[key]) != 'function' && key != 'base' )
			{
				delete base[key];
			}
		}
	}
	this.base = base;
};

Object.prototype.AttachEvent = function(eventName, eventHandler)
{
	if ( typeof(eventName) != 'string' || typeof(eventHandler) != 'function' )
	{
		return new Error(L_ErrorParametersType);
	}
	if ( eventName[0] != 'e' || eventName[1] != '_' )
	{
		eventName = 'e_' + eventName;
	}
	var evt = this[eventName];
	if ( typeof(evt) != 'undefined' )
	{
		if ( __typeof__(evt) == 'EventHandler' )
		{
			evt.AttachHandler(eventHandler);
		}
		else
		{
			this[eventName] = new EventHandler(this, eventName, eventHandler);
		}
	}
};

Object.prototype.GetExpandoKeys = function()
{
	var keys = [];
	var obj = new this.constructor();
	for ( var key in this )
	{
		if ( this[key] !== obj[key] )
		{
			keys.push(key);
		}
	}
	return keys;
};

var _st = window.setTimeout;

window.setTimeout = function(fRef, mDelay) 
{
    try
    {
        if(typeof fRef == 'function')
        {
            var argu = Array.prototype.slice.call(arguments,2);
            var f = (function()
            { 
                fRef.apply(null, argu); 
            });
            
            return _st(f, mDelay);
        }
        return _st(fRef,mDelay);
    }
    catch(e)
    {}
};

function __typeof__(objClass)
{
	if ( objClass != undefined && objClass.constructor )
	{
		var strFun = objClass.constructor.toString();
		var className = strFun.substr(0, strFun.indexOf('('));
		className = className.replace('function', '');
		className = className.replace(/(^\s*)|(\s*$)/ig, '')
		return className ? className : 'Anonymous';
	}
	return typeof(objClass);
}

function createElement(type) 
{
	return $C(type);
}

function removeElement(element) 
{
	try 
	{
		if (element) 
		{
			element.parentNode.removeChild(element);
		}
	}
	catch (e) {
	}
}

function hideElement(element) 
{
	if (element) 
	{
		element.style.display = "none";
	}
}

function hideElementV(element) 
{
	if (element) 
	{
		element.style.visibility = "hidden";
		element.style.display = "";
	}
}

function showElement(element) 
{
	if (element) 
	{
		element.style.display = "";
		element.style.visibility = "";
	}
}

function clearElement(element) 
{
	for (var i in element) 
	{
		try 
		{
			
			element[i] = null;
		}
		catch (e) 
		{
			continue;
		}
	}
}

function getWindowSize() 
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return([myWidth,myHeight]);
}

function GetOffsetPos(element) 
{
	var flag = element.tagName.toUpperCase() == "INPUT" ? true : false;
	var posTop = 0, posLeft = 0;
	do 
	{
		posTop += element.offsetTop || 0;
		posLeft += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
    return [posLeft, posTop];
}

function hideSelects(zIndexNow) 
{
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) 
	{
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) 
		{
			if (selects[i].zIndexNow != zIndexNow && selects[i].style.visibility != "hidden") 
			{
				selects[i].style.visibility = "hidden";
				selects[i].zIndexNow = zIndexNow;
			}
		}
	}
}

function showSelects(zIndexNow) 
{
	if (navigator.appVersion.indexOf("MSIE 6.0") != -1) 
	{
		var selects = document.getElementsByTagName("select");
		var length = selects.length;
		for (var i = 0; i < length; i++) 
		{
			if (selects[i].zIndexNow == zIndexNow) 
			{
				selects[i].style.visibility = "";
				selects[i].zIndexNow = -1;
			}
		}
	}
}

var LoaderScript = function () {
	this.elementContainer = null;
	this.charset = "utf-8";
	this.init = function (stringContainerId) {
		if (stringContainerId) {
			this.elementContainer = document.getElementById(stringContainerId);
		}
		else {
			this.elementContainer = document.createElement("div");
			this.elementContainer.style.display = "none";
			document.body.appendChild(this.elementContainer);
		}
	};
	this.load = function (src, callback, valueCallback) {
		var elementLoader = document.createElement("script");
		elementLoader.type = "text/javascript";
		elementLoader.language = "javascript";
		elementLoader.charset = this.charset;
		elementLoader.src = src;
		elementLoader.valueCallback = valueCallback;
		elementLoader[document.all ? "onreadystatechange" : "onload"] = this.unload;
		elementLoader.callback = callback;
		this.elementContainer.appendChild(elementLoader);
	};
	this.unload = function () {
		if (document.all) {
			if (this.readyState != "loaded" && this.readyState != "complete") {
				return;
			}
		}
		if (this.callback) {
			this.callback(this.valueCallback);
		}
		this.callback = null;
		this[document.all ? "onreadystatechange" : "onload"] = null;
		this.parentNode.removeChild(this);
	};
};

var LoaderAjax = function () {
	this.createXMLHttpObject = function () {
		try {
			return new XMLHttpRequest();
		}
		catch (e) {
		}
		try {
			return new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e) {
		}
		try {
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e) {
		}
		return null;
	};
	this.load = function (url, callback, content) {
		var xmlhttp = this.createXMLHttpObject();
		if (xmlhttp != null) {
			xmlhttp.open("post", url, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader("Content-Type","text/xml");
			xmlhttp.setRequestHeader("Content-Type","utf-8");
			xmlhttp.onreadystatechange = function () {
				if (xmlhttp.readyState == 4) {
					if (xmlhttp.status == 200) {
						var text = xmlhttp.responseText;
						xmlhttp.abort();
						xmlhttp = null;
						callback(text);
					}
				}
			};
			content = content == undefined ? null : content;
			xmlhttp.send(content);
		}
	};
};

var loaderStylesheet = function() {
    this.load = function(cssFile) {

        var head = document.getElementsByTagName('head').item(0);
        css = document.createElement('link');
        css.href = cssFile;
        css.rel = 'stylesheet';
        css.type = 'text/css';
        head.appendChild(css);
        
    }
}

var Model = function (stringType, stringContainerId) {
	this.getRandomString = function () {
		var date = new Date();
		return date.getTime();
	};
	this.stringType = stringType.toLowerCase();
	this.responseText = null;
	this.booleanReturnForced = false;
	switch (this.stringType) {
		case "ajax":
			this.loader = new LoaderAjax();
			break;
		case "script":
			this.loader = new LoaderScript();
			this.loader.init(stringContainerId);
			break;
	    case "css":
	        this.loader = new loaderStylesheet();
	        break;
	}
	this.stringUrl = "";
	this.stringMark = "@RANDOM@";
	this.callback = function (responseText) {
		var model = arguments.callee.model;
		switch (model.stringType) {
			case "ajax":
				if ((model.responseText != responseText || model.booleanReturnForced) && responseText != "") {
					model.responseText = responseText;
					model.processData.model = model;
					model.processData(responseText);
					model.updateView();
				}
				break;
			case "script":
				model.processData(responseText);
				model.updateView(responseText);
				break;
		}
	};
	this.callback.model = this;
	this.processData = function () {};
	this.updateView = function () {};
	this.stringContent = null;
	this.intThread = -1;
	this.intInterval = 5000;
	this.start = function () {
		this.stop();
		this.load();
		this.intThread = setInterval(this.load, this.intInterval);
	};
	this.stop = function () {
		if (this.intThread != -1) {
			clearInterval(this.intThread);
		}
		this.intThread = -1;
	};
	this.arrayUrl = [];
	this.loadScriptUrl = function () {
		var model = arguments.callee.model;
		if (model.arrayUrl.length > 0) {
			var stringUrl = model.arrayUrl.shift();
			model.loader.load(stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, stringUrl);
		}
	};
	this.loadScriptUrl.model = this;
	this.load = function () {
		var model = arguments.callee.model;
		switch (model.stringType) {
			case "ajax":
				model.loader.load(model.stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, model.stringContent);
				break;
			case "script":
				if (model.stringUrl.constructor == Array) {
					model.arrayUrl = [];
					for (var i = 0; i < model.stringUrl.length; i++) {
						model.arrayUrl.push(model.stringUrl[i]);
						setTimeout(model.loadScriptUrl, i * 5000);
					}
				}
				else if (model.stringUrl != "") {
					model.loader.load(model.stringUrl.replace(model.stringMark, model.getRandomString()), model.callback, model.stringUrl);
				}
				break;
			case "css":
			    if( model.stringUrl != "" ) {
			        model.loader.load(model.stringUrl.replace(model.stringMark, model.getRandomString()));
			    }
			    break;
		}
	};
	this.load.model = this;
};

function __JavascriptLoader(url, fnCallback)
{
    var mod = new Model("script");
    mod.stringUrl = url;
    var _fnCall_ = fnCallback;
    if( typeof(_fnCall_) == 'function' && arguments.length > 2 )
    {
        var argus = Array.prototype.slice.call(arguments, 2);
        var fn = (function()
        {
            _fnCall_.apply(null, argus);
        });
        
        mod.processData = function(text)
        {
            try
            {
                fn();
            }
            catch(e)
            {}
        };      
    }
    else
    {
        mod.processData = function(text)
        {
            try
            {
                fnCallback();
            }
            catch(e)
            {}
        };
    }

    mod.load();
}

function __AjaxLoader(url, fnCallback, stringContent)
{
    var mod = new Model("ajax");
    mod.stringUrl = url;
    mod.stringContent = stringContent;
    var _fnCall_ = fnCallback;
    if( typeof(_fnCall_) == 'function' && arguments.length > 3 )
    {
        var argus = Array.prototype.slice.call(arguments, 3);
        mod.processData = function(text)
        {
            argus.push(text);
            var fn = (function()
            {
                _fnCall_.apply(null, argus);
            });
            try
            {
                fn();
            }
            catch(e)
            {}
        };      
    }
    else
    {
        mod.processData = function(text)
        {
            try
            {
                fnCallback(text);
            }
            catch(e)
            {}
        };
    }

    mod.load();
}

function __CssLoader(url)
{
    var mod = new Model("css");
    mod.stringUrl = url;
    mod.load();
}

function OnStylesheetInit(aryCssList)
{
    var type = __typeof__(aryCssList);
    if( type == "Array" )
    {
        for( var i=0; i<aryCssList.length; ++i )
        {
            var ary = aryCssList[i];
            if( ary )
            {
                __CssLoader(ary);
            }
        }
    }
    else if( type == "String" )
    {
        __CssLoader(aryCssList);
    }
}

function OnJavascriptInit(aryJsList)
{
    var type = __typeof__(aryJsList);
    var fn = new Function();
    if( type == "Array" )
    {
        for(var i=0; i<aryJsList.length; ++i )
        {
            var ary = aryJsList[i];
            if( ary )
            {
                __JavascriptLoader(ary, fn);
            }
        }
    }
    else if( type == "String" )
    {
        __JavascriptLoader(aryJsList, fn);
    }
}